
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<div id="ctab" class="tab-pane">
	<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

		<div class="col-lg-12 text-right" style="padding-right: 0px;">
			<button id="addButton" class="btn btn-info btn-sm" type="button" ><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold">新增期间</span></button>
			<%-- 
			<button id="searchButton" class="btn btn-default btn-sm" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
			--%>
		</div><br/>

		<div class="table-responsive">
			<table class="table table-stripped table-hover table-bordered border-top">

				<thead>
					<tr>
						<th width="5%">序号</th>
						<th>期间编码</th>
						<th>期间名称</th>
						<th>期间年度</th>
						<th>期间季度</th>
						<th>开始日期</th>
						<th>结束日期</th>
						<th>调整标识</th>
						<th>创建人</th>
						<th width="6%">期间状态</th>
						<th width="10%">操作</th>
					</tr>
				</thead>
				<tbody>
					
					<c:forEach items="${requestScope.mdFinanceCalendarPeriodList}" var="data" varStatus="status">
					<tr>
						<td>${status.count}</td>
						<td>${data.periodCode}</td>
						<td>${data.periodName}</td>
						<td>${data.periodYear}</td>
						<td>${data.periodQuarter}</td>
						<td><fmt:formatDate value="${data.periodStartDate}" pattern="yyyy-MM-dd"/></td>
						<td><fmt:formatDate value="${data.periodEndDate}" pattern="yyyy-MM-dd"/></td>
						<td>${data.adjustFlag}</td>
						<td>${data.createdBy}</td>
						<td style="text-align: center;">
						<c:choose>
						   <c:when test="${data.periodStatus=='OPEN'}">
						       <span class="label label-primary">打开</span>
						   </c:when>
						   <c:otherwise>
						       <span class="label label-danger">关闭</span>
						   </c:otherwise>
						</c:choose>
						</td>
						<td>
							<div class="btn-group">
								<button class="btn-white btn btn-xs" onclick="editLineData(${data.periodId})"><i class="fa fa-edit"></i>&nbsp;编辑</button>&nbsp;
								<button class="btn-white btn btn-xs" onclick="deleteLineData(${data.periodId})"><i class="fa fa-trash"></i>&nbsp;删除</button>
							</div>
						</td>
					</tr>
					</c:forEach>
					
				</tbody>
				<tfoot>
					<%-- 导入页码 --%>
					<jsp:include page="../../common/pages.jsp"></jsp:include>
				</tfoot>
			</table>

		</div>

	</div>
</div>

<div id="addLineModal"></div>

<script>
	$(document).ready(function() {
		$("#addButton").click(function(){
		    getAddLineModal();
		});
		
		$("#searchButton").click(function(){
		    if($("#searchDiv").css("display")=="none"){
		        $("#searchDiv").show();
		        $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;关闭查询');
		        $("#searchButton").addClass("btn-outline btn-warning");
		        $("#searchButton").blur();
		    }else{
		        $("#searchDiv").hide();
		        $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;展开查询');
		        $("#searchButton").removeClass("btn-outline btn-warning");
		        $("#searchButton").blur();
		    }
		});
	});
	
	function editLineData(id){
		getAddLineModal(id);
	}
	
	function deleteLineData(id) {
		redragonJS.confirm("确认删除数据？", function(){
			deleteLine(id);
		});
	}
	
	function getAddLineModal(id){
		$.ajax({
			type: "post",
			url: "web/mdFinanceCalendarPeriod/getMdFinanceCalendarPeriod",
			data: {"periodId": id, "calendarCode": "${param.calendarCode}"},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				if(data!=""){
					$("#addLineModal").html(data);
					$('#addLineDiv').modal('show');
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
	
	function deleteLine(id){
		$.ajax({
			type: "post",
			url: "web/mdFinanceCalendarPeriod/deleteMdFinanceCalendarPeriod",
			data: {"periodId": id, "calendarCode": "${param.calendarCode}"},
			async: false,
			dataType: "html",
			cache: false,
			success: function(data){
				var json = JSON.parse(data);
				if(json.result=="success"){
					redragonJS.close();
					getLineTab("${param.calendarCode}");
				}else{
					redragonJS.alert("删除期间行错误");
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown){
				redragonJS.alert(textStatus);
			}
		});
	}
</script> 